package Controller;

import DAOs.PeasantJpaController;
import DAOs.exceptions.NonexistentEntityException;
import Entity.Peasant;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;

/**
 *
 * @author Esteban
 */
public class PeasantController {
     EntityManagerFactory emf;
     EntityManager em;
     PeasantJpaController peasantDao;
             
     public PeasantController(EntityManagerFactory emf){
        peasantDao = new PeasantJpaController(emf);
     }
        
    public void createPeasant(String name, String lastname, int phoneNumber, int Age, String Profession, String nativePeasant){
        Peasant p = new Peasant(name, lastname, phoneNumber);
        peasantDao.create(p);
    }
    
    public void updatePeasant(String name, String lastname, int phoneNumber, int Age, String Profession, String nativePeasant) throws NonexistentEntityException, Exception{
        Peasant p = new Peasant(name, lastname, phoneNumber);
        peasantDao.edit(p);
    }
    
    public void deletePeasant(String name, String lastname, int phoneNumber, int Age, String Profession, String nativePeasant) throws NonexistentEntityException{
        Peasant p = new Peasant(name, lastname, phoneNumber);
        peasantDao.destroy(p.getId());
    }
}
